/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal;

import org.rcgwt.client.ui.grid.internal.model.ICellModel;
import org.rcgwt.client.ui.grid.internal.model.IColumnModel;
import org.rcgwt.client.ui.grid.internal.model.IElementModel;
import org.rcgwt.client.ui.grid.internal.model.IRowModel;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class CellModel extends AbstractElementModel implements ICellModel {

    protected IRowModel rowModel;

    protected IColumnModel columnModel;

    protected CellModel() {

    }

    @Override
    public Type getType() {
        return Type.CELL;
    }

    protected void set(int stateMask, IRowModel row, IColumnModel columnModel) {
        this.rowModel = row;
        this.columnModel = columnModel;

        this.set(columnModel.getModelIndex(), stateMask);
    }

    @Override
    protected void constructKey(IKey key) {
        super.constructKey(key);

        rowModel.appendKey(key);

        columnModel.appendKey(key);
    }

    @Override
    public IColumnModel getColumnModel() {
        return columnModel;
    }

    @Override
    public IElementModel getParent() {
        return getRowModel();
    }

    @Override
    public IRowModel getRowModel() {
        return rowModel;
    }

    @Override
    public String toString() {
        return "[Cell modelIndex=" + modelIndex + " state=0x"
                + Integer.toHexString(stateMask) + " row='" + getRowModel()
                + "']";
    }

}